using UnityEngine;

public class BuildingAIController : AIController
{
	public WeaponFight weapon;

	private float intertime;

	public bool canFight;

	private void Start()
	{
		init_build();
	}

	public void init_build()
	{
		if (!isinit)
		{
			m_transform = base.transform;
			maincam = plane_smothfollow.instance.mainCam;
			effectpoint = bodyself;
			lowhpsmoke = null;
			explosionobj = null;
			if (canFight && weapon != null)
			{
				weapon.isfriendweapon = false;
				weapon.parent_num = TypeIndex;
			}
			isinit = true;
		}
	}

	public void init_info(Attribute curatt)
	{
		isdie = false;
		Cur_att = curatt;
		if (weapon != null)
		{
			if (weapon.ismachinegun)
			{
				weapon.hurtdamage = curatt.curweapon.machgun;
				weapon.penetrationVal = curatt.curweapon.machgun_pen;
			}
			else
			{
				weapon.hurtdamage = curatt.curweapon.missile;
				weapon.penetrationVal = curatt.curweapon.missile_pen;
			}
		}
		health_con.set_heal(curatt.curhealatt);
	}

	public override void Reset_AI()
	{
		base.Reset_AI();
		init_build();
		init_info(Cur_att);
		changeHP();
	}

	private void Update()
	{
		if (isdie)
		{
			diedfun();
			diedmove();
			return;
		}
		findTarget();
		if (!canFight)
		{
			return;
		}
		intertime += Time.deltaTime;
		if (!(intertime > 2f))
		{
			return;
		}
		intertime = 0f;
		if (!(targetTrans != null))
		{
			return;
		}
		if (Vector3.Distance(m_transform.position, targetTrans.position) < FightDistance * 2f)
		{
			if (weapon != null)
			{
				weapon.fighttarget = targetTrans;
				weapon.target_fri = targetFri;
			}
		}
		else if (weapon != null)
		{
			weapon.fighttarget = null;
			weapon.target_fri = null;
		}
	}

	public void diedmove()
	{
		m_transform.Translate(0f, Time.deltaTime * -20f, 0f);
	}
}
